﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Net;
using System.Net.Sockets;

public class TestUdpSp : MonoBehaviour
{

	// Use this for initialization
    Socket serverSocket = null;
    IPEndPoint endPoint = null;
    public int port = 8088;
    public string message = "";

	void Start () 
    {
        serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
        endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
	}

    void OnGUI()
    {
        if (GUILayout.Button("Send"))
        {
            if (string.IsNullOrEmpty(message))
            {
                return;
            }

            if (serverSocket == null)
            {
                return;
            }

            if (endPoint == null)
            {
                return;
            }

            Debug.Log("Send");

            serverSocket.SendTo(System.Text.Encoding.UTF8.GetBytes(message), endPoint);

        }
    }
	
	
}
